/////////////////////////////////////////////////////////////////////////////
// Name:        ax_menu_toggle.h
// Purpose:     Toggle menu classes
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_MENU_TOGGLE_H_
#define _AX_MENU_TOGGLE_H_

/*
 * Includes
 */

#include "ax/ax_menu.h"
#include "ax/ax_activator.h"
#include "ax/ax_validator.h"

/**
    @class AxToggleMenuItem

    This is a menu item with two states. On activation, the value is toggled.

    @a label and @a description can both contain the %VALUE% keyword,
    which will be substituted with the current value.

    When the value is changed, a @c wxEVT_COMMAND_CHECKBOX_CLICKED event
    is generated.

    @category{ax}
 */

class AxToggleMenuItem: public AxMenuItem
{
    DECLARE_DYNAMIC_CLASS( AxToggleMenuItem )

public:
// Constructors

    AxToggleMenuItem(const AxToggleMenuItem& item) { Copy(item); }
    AxToggleMenuItem() {}
    AxToggleMenuItem(const wxString& uncheckedLabel,
        const wxString& checkedLabel,
        const wxString& description,
        const wxString& id = wxEmptyString,
        bool value = false);

    void Copy(const AxToggleMenuItem& item)
    {
        AxMenuItem::Copy(item);

        m_checked = item.m_checked;
        m_uncheckedLabel = item.m_uncheckedLabel;
        m_checkedLabel = item.m_checkedLabel;
    }

    virtual AxMenuItem* Clone() { return new AxToggleMenuItem(* this); }

    bool IsChecked() const { return m_checked; }
    virtual bool Check(bool checked);

    void UpdateToggleLabel();

    void SendToggleUpdate(bool value);

    void SetUncheckedLabel(const wxString& label) { m_uncheckedLabel = label; }
    const wxString& GetUncheckedLabel() const { return m_uncheckedLabel; }

    void SetCheckedLabel(const wxString& label) { m_checkedLabel = label; }
    const wxString& GetCheckedLabel() const { return m_checkedLabel; }

protected:

    bool            m_checked;
    wxString        m_uncheckedLabel;
    wxString        m_checkedLabel;
};

/**
    @class AxToggleActivator

    Sets the value of a boolean variable when toggled.

    @category{ax}
 */

class AxToggleActivator: public AxActivator
{
    DECLARE_DYNAMIC_CLASS( AxToggleActivator )

public:
// Constructors

    AxToggleActivator() { Init(); }
    AxToggleActivator(const AxToggleActivator& activator) { Init(); Copy(activator); }

    ~AxToggleActivator() {}

// Operations

    void Init() { }

    virtual AxActivator* Clone() const { return new AxToggleActivator(*this); }

    void Copy(const AxToggleActivator& activator);

    /// Called when the user activates a menu item by pressing return or double-clicking
    virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item);

    /// Called just before the menu item is displayed.
    virtual bool BeforeDisplay(AxMenuController* controller, AxMenuItem* item);

    /// Called during display, at intervals.
    virtual bool UpdateUI(AxMenuController* controller, AxMenuItem* item);

    AxToggleMenuItem* GetToggleMenuItem() const;

protected:
};

/**
    @class AxToggleValidator
 */

class AxToggleValidator: public AxValidator
{
    DECLARE_DYNAMIC_CLASS( AxToggleValidator )

public:
// Constructors

    AxToggleValidator(const AxToggleValidator& validator) { Init(); Copy(validator); }
    AxToggleValidator(bool* ptr) { Init(); m_boolPtr = ptr; }
    AxToggleValidator() { Init(); }
    ~AxToggleValidator() {}

// Operations

    void Copy(const AxToggleValidator& validator)
    {
        AxValidator::Copy(validator);

        m_boolPtr = validator.m_boolPtr;
    }

    virtual AxValidator* Clone() const { return new AxToggleValidator(*this); }

    /// Override to pass a value from the UI to a data structure
    virtual bool TransferDataFromMenu();

    /// Override to pass a value from a data structure to the UI
    virtual bool TransferDataToMenu();

    /// Initialize variables
    void Init() { m_boolPtr = NULL; }

protected:
    bool*        m_boolPtr;
};

#endif
    // _AX_MENU_TOGGLE_H_
